from django.shortcuts import render
from Teach.models import *
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponseNotFound, HttpResponseServerError, HttpResponseForbidden, JsonResponse
from django.views.decorators.csrf import csrf_exempt

# First Page
def first(request):
    ss = Student.objects.get(name='mark', age=22, sex='female')
    return render(request, 'one.html', {'s': ss})

# Second Page
def second(request):
    return render(request, 'two.html')

# info Page
def info(request, name:str, age:int, sex:str):
    try:
        s = Student.objects.get(name=name, age=age, sex=sex)
    except ObjectDoesNotExist:
        return HttpResponseNotFound()
    return render(request, 'student.html', {'stu': s})

# API List
# API Example
@csrf_exempt
def api_example(request):
    if request.is_ajax():
        if request.method == 'POST':
            return JsonResponse({"status": "OK"})
        else:
            return HttpResponseForbidden()
    else:
        return HttpResponseServerError()